﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HttpLoadBalancer
{
    public class ProcessInfo
    {
        public ProcessInfo(string filename, string url)
        {
            Process = new Process();
            Url = url;
            Process.Exited += new EventHandler(Process_Exited);
            Process.ErrorDataReceived += new DataReceivedEventHandler(this.Process_ErrorDataReceived);
            Process.StartInfo = new ProcessStartInfo
            {
                FileName = filename,
                Arguments = url,
                CreateNoWindow =true,
                UseShellExecute =true,
                WindowStyle =ProcessWindowStyle.Minimized
            };
            HasExited = false;
            ErrorInfo = "(None)";
        }


        private void Process_Exited(object sender, EventArgs e)
        {
            HasExited = true;
        }
        private void Process_ErrorDataReceived(object sender, DataReceivedEventArgs e)
        {
            ErrorInfo = e.Data;
        }


        public void Start()
        {
            Process.Start();
        }
        public string Url { get; set; }
        public Process Process { get; set; }
        public string ErrorInfo { get; set; }
        public bool HasExited { get; set; }
        public TimeSpan TotalProcessorTime
        {
            get
            {
                return Process.TotalProcessorTime;
            }
            set
            {
                TotalProcessorTime = value;
            }
        }
    }
}
